#!/usr/bin/python3
# import serial
# import time
# ser = serial.Serial('/dev/ttyS1', 115200)
# ser.write("@N999X0054Y0100T0\r\n".encode())

# time.sleep(1)
# ser.write("@N003X0215Y0125T1\r\n".encode())
# #ser.write("@N003X0246Y-021T1\r\n".encode())
# # time.sleep(1)
# # while True:
# #     ser.write("@N003X-226Y-118T0\r\n".encode())
# #     time.sleep(1)

# import os
# import time

# def Laser_Init():
#         os.system("gpio mode 10 out")
#         os.system("gpio mode 13 out")
#         os.system("gpio write 10 1")
#         os.system("gpio write 13 1")

# def Laser_Control(laser_id,state):
#     if laser_id == 1 and state == 0:
#         os.system("gpio write 10 1")
#     if laser_id == 1 and state == 1:
#         os.system("gpio write 10 0")
#     if laser_id == 0 and state == 0:
#         os.system("gpio write 13 1")
#     if laser_id == 0 and state == 1:
#         os.system("gpio write 13 0")

# Laser_Init()
# while True:
#     Laser_Control(0, 1)
#     time.sleep(1)
#     Laser_Control(0, 0)
#     time.sleep(1)





# def callback(event):
#     rospy.loginfo(rospy.get_time())

# rospy.init_node('test_node', anonymous=True)
# rospy.Timer(rospy.Duration(1), callback)


# rospy.spin()







import serial
import time

# 串口配置
ser = serial.Serial('/dev/ttyS6', 115200)

# 初始位置
x = 270
y = 170

# 走位的边界
x_min, x_max = 40, 440
y_min, y_max = 40, 360

# 移动方向控制
move_x = 1  # 1 表示从左到右，-1 表示从右到左
move_y = 1  # 1 表示从上到下，-1 表示从下到上

while True:
    # 发送当前坐标到串口
    ser.write(f"@X{x:04d}Y{y:04d}T1\r\n".encode())
    
    # # 更新 x, y 坐标，蛇形路径
    # if move_x == 1:  # x 从左到右
    #     x += 40
    #     if x >= x_max:
    #         x = x_max
    #         move_x = -1  # 方向切换到从右到左
    #         y += 120  # 换行，y增加
    #         if y > y_max:
    #             y = y_max
    # else:  # x 从右到左
    #     x -= 40
    #     if x <= x_min:
    #         x = x_min
    #         move_x = 1  # 方向切换到从左到右
    #         y += 120  # 换行，y增加
    #         if y > y_max:
    #             y = y_max

    # # 延时 1 秒
    # time.sleep(1)
